<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        table {
            border-collapse: collapse;
            text-align: center;
            width: 400px;
        }
    </style>
</head>

<body>
    <div class="box">
        <table border='1px'>
            <caption><button id='btn'>反选</button></caption>
            <thead>
                <tr>
                    <th><input type="checkbox" class='checkall'>全选/全不选</th>
                    <th>名称</th>
                    <th>厂家</th>
                    <th>价格</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><input type="checkbox" class='check'></td>
                    <td>ipad</td>
                    <td>apple</td>
                    <td>6666</td>
                </tr>
                <tr>
                    <td><input type="checkbox" class='check'></td>
                    <td>iphone</td>
                    <td>apple</td>
                    <td>7777</td>
                </tr>
                <tr>
                    <td><input type="checkbox" class='check'></td>
                    <td>ipro</td>
                    <td>apple</td>
                    <td>8888</td>
                </tr>
            </tbody>
        </table>
    </div>
    <script src='../jquery-1.12.4.js'></script>
    <script>
        $(function(){
            $('.checkall').bind('click',function(){
                $('.check').prop('checked', $(this).prop('checked'))
            })
            $('.check').click(function(){
                $('.checkall').prop('checked',$('.check:checked').length == $('.check').length)
            })
            $('#btn').click(function(){
                var str = $('.check:checked')
                $('.check:not(:checked)').prop('checked',true)
                str.prop('checked',false)
                $('.checkall').prop('checked',$('.check:checked').length == $('.check').length)
            })
        })
    </script>
</body>

</html>